//
//  SelectLocaitonController.m
//  LoveExpress
//
//  Created by 刘甲奇 on 2017/6/1.
//  Copyright © 2017年 dongfanghong. All rights reserved.
//

#import "SelectLocaitonController.h"

@interface SelectLocaitonController ()
/**
 <#Description#>
 */
@property(nonatomic,strong)NSMutableArray *dataSource;
@end

@implementation SelectLocaitonController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"haha"];
    self.title = @"选择地区";
    
    [self loadData];
    
}
- (void)loadData
{
    NSDictionary *dict01 = @{@"name":@"济南市历城区",@"url":@"http://124.128.208.58:81/shop_lc/"};
    NSDictionary *dict02 = @{@"name":@"济南市章丘区",@"url":@"http://zq.sdshequ.org:81/shop/"};
    NSDictionary *dict03 = @{@"name":@"淄博市张店区",@"url":@"http://58.57.98.122:81/shopnc_new/"};
    NSDictionary *dict04 = @{@"name":@"临沂市沂水县",@"url":@"http://221.2.92.70:81/shopnc_v2/"};
//    NSDictionary *dict05 = @{@"name":@"章丘测试",@"url":@"http://192.168.18.47/shop_zq/"};
//    NSDictionary *dict06 = @{@"name":@"外网测试",@"url":@"http://124.128.3.210:9995/shopnc_v2/"};
    
    [self.dataSource addObject:dict01];
    [self.dataSource addObject:dict02];
    [self.dataSource addObject:dict03];
    [self.dataSource addObject:dict04];
//    [self.dataSource addObject:dict05];
//    [self.dataSource addObject:dict06];
    [self.tableView reloadData];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"haha" forIndexPath:indexPath];
    
    cell.textLabel.text = self.dataSource[indexPath.row][@"name"];
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    cell.textLabel.textColor = [UIColor darkGrayColor];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //发送通知,然后消失页面
    [self dismissViewControllerAnimated:YES completion:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:SELECT_LOCATION_NOTIFICATION object:self.dataSource[indexPath.row]];
}

#pragma mark- getter
- (NSMutableArray *)dataSource
{
    if (_dataSource == nil) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}


@end
